﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TestingSystem
{
    public partial class Main : Form
    {
        private int childFormNumber = 0;
        private Login.Login loginForm;
        private bool isLogin = false;

        public Main()
        {
            InitializeComponent();
            loginForm = new Login.Login();
        }

        private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void StatusBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            statusStrip.Visible = statusBarToolStripMenuItem.Checked;
        }

        private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }

        private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.ArrangeIcons);
        }

        private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form childForm in MdiChildren)
            {
                childForm.Close();
            }
        }

        private void manageQuestionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            QuestionManager.QuestionManager form = new QuestionManager.QuestionManager();
            form.MdiParent = this;
            form.Show();
        }

        private void manageTestingToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TestingManager.TestingManagerForm form = new TestingManager.TestingManagerForm();
            form.MdiParent = this;
            form.Show();
        }

        private void ShowLoginForm(object sender, EventArgs e)
        {
            if (isLogin == false)
            {
                if (loginForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    this.manageTestingToolStripMenuItem.Enabled = true;
                    this.manageQuestionToolStripMenuItem.Enabled = true;
                    this.isLogin = true;
                    this.loginToolStripMenuItem.Text = "Logout";
                }
            }
            else
            {
                this.manageQuestionToolStripMenuItem.Enabled = false;
                this.manageTestingToolStripMenuItem.Enabled = false;
                this.isLogin = false;
                this.loginToolStripMenuItem.Text = "Login";
            }
        }
    }
}
